class AuthorsController < ApplicationController

#  TODO: For all conrollers, add pagination.  Add to all views (via CSS) a
#  background image.   Add sorting to the view.  Add a search on Author, Story, and Summary fields
#  add books as polymorphic parallel models to the serials, with relationship to story
#  Develop a masthead for the top of the page.

  # GET /authors
  # GET /authors.xml
  def index
    @author = Author.find(:all)

    @page_title = "Authors Listing"
    # TODO: pagination, sorting, filtering, searching
    # TODO:  all the above for all controllers/views
    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @author.to_xml }
    end
  end

  # GET /authors/1
  # GET /authors/1.xml
  def show
    @author = Author.find(params[:id])
    @page_title = 'Show Author - ' + @author.name
    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @author.to_xml }
    end
  end

  # GET /authors/new
  def new
    @author = Author.new
    @page_title = ' New Author '
  end

  # GET /authors/1;edit
  def edit
    @author = Author.find(params[:id])
    @page_title = ' Edit Author - ' + @author.name
  end

  # POST /authors
  # POST /authors.xml
  def create
    @author = Author.new(params[:author])
    @page_title = ' Create Author '

    respond_to do |format|
      if @author.save
        flash[:notice] = 'Author was successfully created.'
        format.html { redirect_to authors_url }
        format.xml  { head :created, :location => author_url(@author) }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @author.errors.to_xml }
      end
    end
  end

  # PUT /authors/1
  # PUT /authors/1.xml
  def update
    @author = Author.find(params[:id])
    @page_title = ' Authors '
    @page_subtitle = ' - ' + @author.name


    respond_to do |format|
      if @author.update_attributes(params[:author])
        flash[:notice] = 'Author was successfully updated.'
        format.html { redirect_to authors_url }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @author.errors.to_xml }
      end
    end
  end

  # DELETE /authors/1
  # DELETE /authors/1.xml
  def destroy
    @author = Author.find(params[:id])
    @author.destroy
    @page_subtitle = ''
    respond_to do |format|
      format.html { redirect_to authors_url }
      format.xml  { head :ok }
    end
  end
end
